// pages/youhuiquan/youhuiuquan.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex: 1,
    toView: 2,
    showClass: false,//是否显示选择标签面板
    yhjFlag:true,
    navlist: [{
      id: 0,
      name: "关注",
    },
    {
      id: 1,
      name: "推荐",
    },
    {
      id: 2,
      name: "营养保健",
    }, {
      id: 3,
      name: "招聘求职",
    }, {
      id: 4,
      name: "美容护肤",
    }, {
      id: 5,
      name: "个人洗护",
    }, {
      id: 6,
      name: "家居收纳",
    }, {
      id: 7,
      name: "出行",
      },  {
        id: 8,
        name: "小家电",
      }],
    itemBg_red:"../images/yhj_red.png",
    itemBg_grey: "../images/yhj_grey.png",
    status:["立即领取","去使用","已领完","已过期"],
    liquUrl:"/pages/images/ling.png",
    guoqiUrl:"/pages/images/guoqi.png",
      yhjList:[{
        id: 1,
        guoqi:false,//是否过期
        money:"100",
        text:"满999元可用",
        title:"美食优惠券",
        subtitle:"通用券，满999元可用",
        date:"2018.3.10-2018.6.30",
        yiling:25,
        types:0,//0-未领取 1-已领取，可用 2-未领取，已领完 3-已领取，已过期
        
      }, {
          id: 2,
          guoqi: true,//是否过期
          money: "100",
          text: "满999元可用",
          title: "美食优惠券",
          subtitle: "通用券，满999元可用",
          date: "2018.3.10-2018.6.30",
          yiling: 25,
          types: 3,//0-未领取 1-已领取，可用 2-未领取，已领完 3-已领取，已过期

        },
        {
          id: 3,
          guoqi: false,//是否过期
          money: "50",
          text: "满299元可用",
          title: "美食优惠券",
          subtitle: "通用券，满299元可用",
          date: "2018.3.10-2018.6.30",
          yiling: 25,
          types: 1,//0-未领取 1-已领取，可用 2-未领取，已领完 3-已领取，已过期

        },
        {
          id: 4,
          guoqi: false,//是否过期
          money: "20",
          text: "满199元可用",
          title: "美妆优惠券",
          subtitle: "通用券，满199元可用",
          date: "2018.3.10-2018.6.30",
          yiling: 25,
          types: 2,//0-未领取 1-已领取，可用 2-未领取，已领完 3-已领取，已过期

        },
        
      ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /*******选择类别**********/
  choseNav: function (e) {
    console.log(e);
    var that = this;
    var offsetX = e.detail.x;
    var activeIndex = e.currentTarget.dataset.index;
    that.loading();
    that.setData({
      activeIndex: activeIndex,
      toview: activeIndex
    })

    if (offsetX < 20) {
      that.setData({
        scrollLeft: 0
      })
    } else if (offsetX > 320) {
      that.setData({
        scrollLeft: 320
      })
    } else {
      that.setData({
        scrollLeft: offsetX - 50
      })
    }

  },

  /***********点击按钮显示更多标签************ */
  getmore: function () {
    var that = this;
    var showClass = that.data.showClass;
    if (!showClass){
      that.setData({
        showClass: true
      })
    }else{
      that.setData({
        showClass: false
      })
    }
    
  },
  //选择标签
  choseClass: function (e) {
    var that = this;
    var activeIndex = e.currentTarget.dataset.index;
    var activeId = e.currentTarget.dataset.id;//传值用
    that.setData({
      activeIndex: activeIndex
    })
    that.choseNav(e);
    setTimeout(function () {
      that.setData({
        showClass: false
      })
    }, 100)

    //请求接口，获取数据
  },
  /*********隐藏选择分类面板*********** */
  hideGrey:function(){
    var that=this;
    that.setData({
      showClass: false
    })
  },
  /*************加载中***** */
  loading:function(){
    wx.showLoading({
      title: '玩命加载中...',
    })
    setTimeout(function(){
      wx.hideLoading()
    },600)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      console.log("到达底部");
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})